﻿#include "stdafx.h"
#include "ScriptMaple.h"
#include "script.h"
#include "GameAppDlg.h"


CScriptMaple::CScriptMaple()
{
}

CScriptMaple::CScriptMaple(int nDmIndex,CDm* dm)
{
	m_DmIndex = nDmIndex;
	m_dm = dm;
}

CScriptMaple::~CScriptMaple()
{
}

//启动游戏客户端
bool CScriptMaple::LoginOpenClient()
{

	long hwnd = 0,nHwnd=0;//窗口句柄
	
	while (m_Flag)
	{
		m_CheckState = false;
		hwnd = m_dm->GetBindWindow();

		//查找代理是否激活

		nHwnd = g_dm->FindWindowW(L"XunYouMainClass_4B32", L"迅游国际版");
		if (nHwnd != 0) {
			g_dm->SetWindowState(nHwnd, 2);
		}
		else {
			g_dm->RunApp(L"D:\\Program Files (x86)\\XunYou_Intl\\xunyou.exe", 0);
		}
		//if (g_dm->GetWindowState(nHwnd)==0) {

		//}
		//解除绑定
		if (hwnd != 0) {
			ShowLog(L"解除绑定");
			m_dm->UnBindWindow();
		}
		//打开游戏
		hwnd = m_dm->FindWindowEx(0, L"", L"MapleStory");
		ShowLog(L"游戏句柄" + NumberToString(hwnd));
		//如果存在游戏句柄则先关闭游戏
		CString strHwnds;
		CStringArray hwndArr;
		if (hwnd != 0) {
			ShowLog(L"游戏开始窗口句柄存在关闭游戏");
			strHwnds = m_dm->EnumProcess(L"GameLauncher.exe");
			ShowLog(L"游戏句柄" + strHwnds);
			StringSplit(strHwnds, hwndArr, ',');
			for (size_t i = 0; i < hwndArr.GetCount(); i++)
			{
				m_dm->TerminateProcess(_wtol(hwndArr[i]));
			}
		}

		strHwnds = m_dm->EnumProcess(L"MapleStory.exe");
		ShowLog(L"游戏句柄" + NumberToString(hwnd));
		if (strHwnds != L"" || strHwnds.GetLength() > 0) {
			ShowLog(L"游戏开始窗口句柄存在关闭游戏");
			hwndArr.RemoveAll();
			StringSplit(strHwnds, hwndArr, ',');
			for (size_t i = 0; i < hwndArr.GetCount(); i++)
			{
				m_dm->TerminateProcess(_wtol(hwndArr[i]));
			}
		}
		ShowLog(L"打开游戏");
		m_dm->RunScript(L"游戏图标");
		hwnd = m_dm->FindWindowEx(0, L"", L"MapleStory");
		
		ScriptDelay(m_DmIndex, 1000);
		m_dm->KeyPressChar(L"tab");
		ScriptDelay(m_DmIndex, 1000);
		m_dm->KeyPressChar(L"enter");
		ScriptDelay(m_DmIndex, 10000);

		for (size_t i = 0; i < 150; i++)
		{
			strHwnds = m_dm->EnumProcess(L"GameLauncher.exe");
			if (strHwnds != L"" || strHwnds.GetLength() > 0) {
				ShowLog(L"登录窗口未关闭重新开始");
				break;
			}

			strHwnds = m_dm->EnumProcess(L"MapleStory.exe");
			if (strHwnds == L"", strHwnds.GetLength() == 0) {
				ShowLog(L"游戏进程不存在重新开始");
				break;
			}

			hwnd = m_dm->FindWindowEx(0, L"MapleStoryClass", L"MapleStory");
			ShowLog(L"等待启动.窗口句柄" + NumberToString(hwnd));
			ScriptDelay(m_DmIndex, 1000);
			//int ret = 0;
			if (hwnd != 0) {
				int ret = m_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
				if (ret == 1) {
					m_dm->MoveWindow(hwnd, 0, 0);
					m_CheckState = true;
					ShowLog(L"窗口绑定成功");
					break;
				}
			}
		}

		for (size_t i = 0; i < 30; i++)
		{
			if (m_dm->RunScript(L"进入登录")) {
				ShowLog(L"游戏开启成功");
				return true;
			}
			ScriptDelay(m_DmIndex, 1000);
		}
	}
	return true;
}

//登录游戏
bool CScriptMaple::LoginGame(bool isRole, bool isLogin)
{
	long x, y;
	m_dm->UseDict(1);
	bool bFlag = false;
	int nCount = 0;
	UINT uTwoPwdNum = 0;
	while (m_Flag)
	{
		if (!FindHwnd()) {
			m_Flag = false;
		}
		ShowLog(L"当前索引" + NumberToString(m_Index));
		SetCodeState(L"账号在线", L"5");
		SetCodeState(L"账号密码错误", L"2");
		SetCodeState(L"二密错误", L"3");
		SetCodeState(L"账号验证", L"7");

		if (isRole) {
			int nRoleNum = g_AccountFile.GetInt(NumberToString(m_Index + 1), L"RoleNum");
			int nZhaNum = g_AccountFile.GetInt(NumberToString(m_Index + 1), L"ZhaNum");
			if (nRoleNum >= nZhaNum) {
				g_main_cwnd->m_list_info.SetItemText(m_Index, 6, L"完成");//当前账号置完成
				g_AccountFile.SetString(NumberToString(m_Index + 1), L"state", L"1");
				return false;
			}
		}
		nCount++;
		if (isLogin) {//为假则执行登录 为真则切换角色
					  //if (nCount > 30) {
					  //	KillProcess(L"MapleStory.exe");
					  //	ScriptDelay(index, 1000);
					  //	return false;
					  //}
					  //输入账号密码
			if (m_dm->RunScript(L"进入登录")) {//到达登录页面
				m_dm->RunScript(L"输入账号", 1, GetItemText(m_Index, 1));
				ShowLog(GetItemText(m_Index, 1));
				ScriptDelay(m_DmIndex, RandomNumber(1000, 1100));
				m_dm->RunScript(L"输入密码", 1, GetItemText(m_Index, 2));
				ShowLog(GetItemText(m_Index, 1));
				ScriptDelay(m_DmIndex, RandomNumber(2000, 2100));
				m_dm->RunScript(L"点击登录");
			}


			//是否存在保号 不存在直接选择第一账号
			CString strBaoHao = GetItemText(m_Index, 11);

			if (strBaoHao != L"" && strBaoHao.GetLength() > 0) {
				ScriptDelay(m_DmIndex, RandomNumber(2000, 2100));
				m_dm->RunScript(L"选择账号", 2, strBaoHao);
			}
			else
			{
				ScriptDelay(m_DmIndex, RandomNumber(2000, 2100));
				m_dm->RunScript(L"选中账号");
			}

			//选择区服线路
			CString strServer = L"loginChoseServer" + GetItemText(m_Index, 4) + L".bmp";
			ShowLog(strServer);
			m_dm->RunScript(L"选择区服", 2, strServer);
			ScriptDelay(m_DmIndex, RandomNumber(1000, 1100));
			//m_dm->RunScript(L"选择线路25");

			if (m_dm->RunScript(L"拥挤")) {
				m_dm->KeyPressChar(L"enter");
			}
			if (m_dm->RunScript(L"线路窗口")) {
				CString strXian = m_dm->RunScripts(L"多线选择", L"chSever.bmp");
				int nCount = strXian.Replace(L"|", L"|");
				if (nCount > 0) {
					int nRndXian = RandomNumber(0, nCount);
					CStringArray xianArr;
					StringSplit(strXian, xianArr, '|');
					CStringArray xianPointArr;
					StringSplit(xianArr.GetAt(nRndXian), xianPointArr, ',');
					m_dm->MoveTo(_wtol(xianPointArr.GetAt(1)) + RandomNumber(5, 15), _wtol(xianPointArr.GetAt(2)) + RandomNumber(5, 10));
					ScriptDelay(m_DmIndex, RandomNumber(500, 1100));
					m_dm->LeftDoubleClick();
					ScriptDelay(m_DmIndex, RandomNumber(500, 800));
				}
			}
			if (m_dm->RunScript(L"拥挤")) {
				m_dm->KeyPressChar(L"enter");
			}

		}

		//返回第一角色页面 切换状态为假
		if (m_dm->RunScript(L"角色页面", &x, &y) && !bFlag && !isRole) {
			for (size_t k = 0; k < 8; k++)
			{
				m_dm->FindPic(418, 616, 488, 650, L"Login_Page1.bmp", L"050505", 1, 0, &x, &y);
				//如果第一个存在
				if (x > 0) {
					bFlag = true;
					break;
				}
				else {
					m_dm->MoveTo(659 + RandomNumber(0, 10), 719 + RandomNumber(0, 3));
					Sleep(RandomNumber(200, 300));
					m_dm->LeftClick();
					Sleep(RandomNumber(1500, 2000));
				}
			}
		}

		//切换角色为真进行角色切换
		if (m_dm->RunScript(L"角色页面") && !bFlag && isRole) {
			int a = 0;
			if (g_main_cwnd->m_ZhaKun.GetCheck() == 1) {
				a = g_AccountFile.GetInt(NumberToString(m_Index + 1), L"RoleNum");
			}
			CString strPage;
			if (a < 12) {// 第一页
				strPage = L"Login_Page1.bmp";
			}if (a >= 12 && a < 25) {//2
				strPage = L"Login_Page2.bmp";
			}if (a >= 24 && a < 37) {//2
				strPage = L"Login_Page3.bmp";
			}if (a >= 36 && a < 49) {//2
				strPage = L"Login_Page4.bmp";
			}
			if (a >= 12) {
				if (a % 12 == 0) {
					a = 0;
				}
				else {
					a = a % 12;
				}
			}
			long x1, y1;
			for (size_t k = 0; k < 5; k++)
			{
				//查找页码
				m_dm->FindPic(405, 613, 450, 653, strPage, L"050505", 1, 0, &x1, &y1);
				if (x1 > 0) {//找到页码
					if (m_dm->RunScript(L"二密窗口")) {
						bFlag = true;
						break;
					}
					m_dm->MoveTo(g_Point[a][0] + RandomNumber(0, 3), g_Point[a][1] + RandomNumber(0, 10));
					m_dm->LeftDoubleClick();
					Sleep(RandomNumber(1000, 2000));
					bFlag = true;
				}
				else {
					m_dm->MoveTo(659 + RandomNumber(0, 10), 719 + RandomNumber(0, 3));
					//m_dm->MoveToEx(659, 719, 10, 3);
					Sleep(RandomNumber(100, 200));
					m_dm->LeftClick();
					Sleep(RandomNumber(1000, 2000));
				}
			}

		}
		//选择角色输入二密
		if (m_dm->RunScript(L"角色页面", &x, &y) && bFlag) {
			m_dm->MoveTo(127 + RandomNumber(1, 5), 312 + RandomNumber(1, 8));
			m_dm->LeftDoubleClick();
			ShowLog(L"到达角色页面");
			ScriptDelay(m_DmIndex, RandomNumber(1300, 1500));
			if (m_dm->RunScript(L"二密窗口")) {
				ShowLog(L"找到二密窗口");
				CString strKeyWord = GetItemText(m_Index, 3); //二密
				CString twoCodeImg;
				for (size_t i = 0; i < strKeyWord.GetLength(); i++)
				{
					CString strbmp = strKeyWord.Mid(i, 1) + L".bmp";
					//CString sTwoCode = L"输入二密" + code.Mid(i, 1);
					if (i == twoCodeImg.GetLength() - 1) {
						twoCodeImg += strbmp;
					}
					else {
						twoCodeImg += strbmp + L"|";
					}
				}

				CString strTwoCodeImgs = m_dm->RunScripts(L"二密查找", twoCodeImg);
				ShowLog(L"二密数据：" + strTwoCodeImgs);
				CStringArray strTwoCodeArr;
				StringSplit(strTwoCodeImgs, strTwoCodeArr, '|');
				//分割二密坐标
				for (size_t i = 0; i < strTwoCodeArr.GetCount(); i++)
				{
					CStringArray strPointArr;
					StringSplit(strTwoCodeArr.GetAt(i), strPointArr, ',');
					ShowLog(strTwoCodeArr.GetAt(i) + L":" + strPointArr.GetAt(1) + L"," + strPointArr.GetAt(2));
					m_dm->MoveTo(_wtol(strPointArr.GetAt(1)) + RandomNumber(5, 10), _wtol(strPointArr.GetAt(2)) + RandomNumber(5, 10));
					ScriptDelay(m_DmIndex, RandomNumber(200, 280));
					m_dm->LeftDown();
					ScriptDelay(m_DmIndex, RandomNumber(80, 150));
					m_dm->LeftUp();
					ScriptDelay(m_DmIndex, RandomNumber(1500, 1700));
					uTwoPwdNum++;
					if (uTwoPwdNum > 50) {
						uTwoPwdNum = 0;
						m_Flag = false;
						break;
					}
					//点击后查找星号数量
					CString strXing = m_dm->RunScripts(L"星号查找", L"pwdxing.bmp");
					int nCount = strXing.Replace(L"|", L"|");
					if (strXing == L"" && strXing.GetLength() == 0) {//未找到星号重新点击
						i = -1;
						continue;
					}
					else if (nCount > i) {//当前点击的星号大于找到的*则重新点击上一个
						ScriptDelay(m_DmIndex, RandomNumber(1500, 1700));
						m_dm->KeyPressChar(L"esc");
						ScriptDelay(m_DmIndex, RandomNumber(1500, 1700));
						break;
					}

				}
				if (m_dm->RunScript(L"二密确认")) {
					for (size_t k = 0; k < 20; k++)
					{
						if (m_dm->RunScript(L"登录成功")) {
							ScriptDelay(m_DmIndex, 1000);
							return true;
						}
					}
				}
			}

		}

		if (m_dm->RunScript(L"登录成功")) {
			//ScriptDelay(index, RandomNumber(5500, 7000));
			if (isRole) {
				//g_nState = 0;
				this->m_State = 0;
			}
			return true;
		}

	}
	return false;
}

//退出扎昆祭台
void CScriptMaple::ExitZkjt()
{
	if (m_dm->RunScript(L"扎昆祭台入口")) {
		m_dm->KeyDownChar(L"left");
		Sleep(200);
		for (size_t i = 0; i < 100; i++)
		{
			m_dm->KeyPressChar(L"up");
		}
		m_dm->KeyUpChar(L"left");
		Sleep(RandomNumber(2000, 2500));
		if (!m_dm->RunScript(L"扎昆祭台入口")) {
			return;
		}
		m_dm->KeyDownChar(L"right");
		Sleep(200);
		for (size_t i = 0; i < 100; i++)
		{
			m_dm->KeyPressChar(L"up");
		}
		m_dm->KeyUpChar(L"right");
	}
}

//退出扎昆入口
void CScriptMaple::ExitZkrk()
{
	long x, y, x1, y1;
	if (m_dm->RunScript(L"扎昆入口")) {
		ShowLog(L"开始退出扎昆地图");
		m_dm->RunScript(L"小地图", &x, &y);
		m_dm->RunScript(L"人物坐标", &x1, &y1);
		if (MovetoX(RandomNumber(139, 143))) {
			Sleep(RandomNumber(2000, 2500));
			m_dm->RunScript(L"npc啊杜比斯");
			Sleep(RandomNumber(2000, 2500));
			for (size_t k = 0; k < 5; k++)
			{
				m_dm->RunScript(L"退出扎昆");
				if (m_dm->RunScript(L"下一步")) {
					m_dm->KeyPressChar(L"space");
					Sleep(RandomNumber(2000, 2500));
				}

			}
		}

	}
}

//乌鲁斯boss结束退出
void CScriptMaple::ExitWls()
{
	for (size_t k = 0; k < 200; k++)
	{
		if (m_dm->RunScript(L"乌鲁斯退出1")) {
			m_dm->KeyDownChar(L"right");
			Sleep(1000);
			for (size_t i = 0; i < 100; i++)
			{
				m_dm->KeyPressChar(L"up");
			}
			m_dm->KeyUpChar(L"right");
			//Sleep(RandomNumber(2000, 2500));
			if (!m_dm->RunScript(L"乌鲁斯地图")) {
				return;
			}
			m_dm->KeyDownChar(L"left");
			Sleep(1000);
			for (size_t i = 0; i < 100; i++)
			{
				m_dm->KeyPressChar(L"up");
			}
			m_dm->KeyUpChar(L"left");
		}
		Sleep(100);
		ShowLog(L"开始退出乌鲁斯");
	}
}

//移动到目的坐标
bool CScriptMaple::MovetoX(int nEndX)
{
	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	m_dm->KeyUp(37);
	m_dm->KeyUp(39);
	m_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		//closeWndTask();

		//}
		//while (true)
		//{
		m_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		nPath = nX - nEndX;
		if (nX - nEndX == 0) {
			m_dm->KeyUp(39);
			m_dm->KeyUp(37);
			return true;
		}
		m_dm->FindPic(0, 0, 1000, 700, L"wndClose.bmp", L"050505", 0.9, 0, &x, &y);
		if (x > 0) {
			m_dm->KeyUp(39);
			m_dm->KeyUp(37);
			return true;
		}
		if (nX - nEndX >= 2) {//往左移动
			m_dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				m_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				Sleep(50);
				if (nX - nEndX == 0) {
					m_dm->KeyUp(37);
					return true;
				}
				if (abs(nX - nEndX) <= 1 || nX - nEndX < -1) {
					m_dm->KeyUp(37);
					return true;
				}
				m_dm->FindPic(0, 0, 1000, 700, L"wndClose.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					m_dm->KeyUp(37);
					return true;
				}

			}
			m_dm->KeyUp(37);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX < -2) {
			//	break;
			//}
		}
		if (nX - nEndX <= -2) {
			m_dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{

				m_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//Sleep(10);
				if (nX - nEndX == 0) {
					m_dm->KeyUp(39);
					return true;
				}
				if (abs(nX - nEndX) <= 1 || nX - nEndX > 1) {
					m_dm->KeyUp(39);
					return true;
				}
				Sleep(50);
				m_dm->FindPic(0, 0, 1000, 700, L"wndClose.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					m_dm->KeyUp(39);
					return true;
				}
			}
			m_dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}
		//if (nPath == nX - nTagX) {
		//	j++;
		//}
		//if (j > 3) {
		//	return false;
		//}
	}
	if (abs(nX - nEndX) <= 1) {
		return true;
	}
	return false;
}


//查找红电脑百分比
bool CScriptMaple::FindComputer()
{
	long x, y;
	if (m_dm->RunScript(L"红电脑")) {
		g_main_cwnd->m_list_info.SetItemText(m_Index, 10, L"红电脑");
		return true;
	}
	if (!m_dm->RunScript(L"设置")) {
		m_dm->KeyPressChar(L"esc");
	}
	Sleep(RandomNumber(1000, 1500));
	if (m_dm->RunScript(L"设置", &x, &y)) {
		m_dm->MoveToEx(x + 15, y + 90, 10, 3);
		m_dm->LeftClick();
		Sleep(RandomNumber(1000, 1500));
		if (m_dm->RunScript(L"电脑列表")) {
			Sleep(RandomNumber(500, 1000));
			if (m_dm->RunScript(L"电脑百分比")) {
				g_main_cwnd->m_list_info.SetItemText(m_Index, 10, L"50%-");
				Sleep(RandomNumber(1000, 1500));
				if (m_dm->RunScript(L"电脑列表")) {
					m_dm->KeyPressChar(L"esc");
					return true;
				}
			}
		}
		Sleep(RandomNumber(1000, 1500));
		if (m_dm->RunScript(L"电脑列表")) {
			m_dm->KeyPressChar(L"esc");
			return true;
		}
	}
	return false;
}


//退出组队
void CScriptMaple::CloseTearm()
{
	if (m_dm->RunScript(L"组队血条")) {
		m_dm->KeyPressChar(L"p");
		ScriptDelay(m_Index, RandomNumber(1000, 1100));
		if (m_dm->RunScript(L"导航窗口")) {
			m_dm->RunScript(L"退出组队");
		}
		ScriptDelay(m_Index, RandomNumber(1000, 1500));
		if (m_dm->RunScript(L"导航窗口")) {
			m_dm->KeyPressChar(L"p");
		}
	}
	else {
		if (m_dm->RunScript(L"导航窗口")) {
			m_dm->RunScript(L"退出组队");
		}
	}

}


//选择Boss
void CScriptMaple::ChoseBoss(CString strBoss, int offX, int offY)
{
	long x, y;
	m_dm->KeyPressChar(L"t");
	ScriptDelay(m_Index, RandomNumber(500, 1000));
	m_dm->RunScript(strBoss, &x, &y);
	ScriptDelay(m_Index, RandomNumber(1000, 1500));
	m_dm->MoveToEx(x + offX, y + offY, 10, 10);
	m_dm->LeftClick();
}

//根据偏移x,y选中Boss
void CScriptMaple::ChoseBoss(int x, int y)
{
	long x1, y1;
	if (m_dm->RunScript(L"导航窗口",&x1,&y1)) {
		m_dm->Click(x1+x, y+y1, 5, 10);
		Sleep(1000);
		m_dm->RunScript(L"go");
		Sleep(1000);
		if (m_dm->RunScript(L"扎昆已刷")) {
			m_State = 9;
		}
		for (size_t i = 0; i < 5; i++)
		{
			if (m_dm->RunScript(L"确定按钮")) {
				Sleep(2000);
			}
		}
	}
	else {
		m_dm->KeyPressChar(L"t");
	}
}



bool CScriptMaple::RunScriptList(CString str)
{
	int istart = 0;
	while (istart != -1) {//分割 @符号
		CString m;
		m = str.Tokenize(L"|", istart);
		//runScript(index, m);
		m_dm->RunScript(m);
		Sleep(100);
	}
	return true;
	
}

//设定类别索引，大漠索引
void CScriptMaple::SetIndex(int i,bool bFlag)
{
	m_Index = i;
	m_Flag = bFlag;
	m_State = 0;
}

//设定UI状态
bool CScriptMaple::SetCodeState(CString ocr, CString state)
{
	if (m_dm->RunScript(ocr)) {
		g_AccountFile.SetString(NumberToString(m_Index + 1), L"state", state);
		g_main_cwnd->m_list_info.SetItemText(m_Index, 6, ocr);
		ScriptDelay(m_DmIndex, 10000);
		m_Flag = false;
		return true;
	}
	return false;
}

void CScriptMaple::SwicthRole(bool isRole, bool isLogin)
{
	long x, y;
	ShowLog(L"切换角色");
	
	while (m_Flag)
	{
		if (!FindHwnd()) {
			m_Flag = false;
		}

		m_dm->RunScript(L"确定按钮");
		if (m_dm->RunScript(L"角色页面")) {
			//是否换号
			if (isLogin) {//为真换号
				m_dm->RunScript(L"退出角色");
				ScriptDelay(m_DmIndex, RandomNumber(1000, 1500));
				m_dm->RunScript(L"确定退出角色");
			}
			else {//为假换角色
				//LoginGameWls(index, taskIndex, isRole, isLogin);
				LoginGame(isRole, isLogin);
				if (isRole) {
					//g_nState = 0;
					m_State = 0;
				}
				return;
			}
		}
		else {
			if (m_dm->RunScript(L"设置按钮", &x, &y)) {
				m_dm->MoveToEx(x + 5, y + 10, 5, 5);
				m_dm->LeftClick();
				ScriptDelay(m_DmIndex, RandomNumber(3000, 3300));
				m_dm->MoveTo(x - 20 + RandomNumber(1, 20), y - 35 + RandomNumber(1, 5));
				m_dm->LeftClick();
				ScriptDelay(m_DmIndex, RandomNumber(1000, 1100));
			}
			if (m_dm->RunScript(L"点击退出")) {
				ScriptDelay(m_DmIndex, RandomNumber(5000, 5100));
			}
		}
		if (m_dm->RunScript(L"进入登录")) {
			//LoginGameWls(index, taskIndex, isRole, isLogin);
			LoginGame(isRole, isLogin);
			if (isRole) {
				m_State = 0;
			}
			return;
		}

	}
}

//退出乌鲁斯地图
void CScriptMaple::ExitWlsMap()
{
	if (m_dm->RunScript(L"乌鲁斯地图")) {
		m_dm->KeyDownChar(L"left");//向左按住
		Sleep(2000);
		for (size_t i = 0; i < 20; i++)
		{
			m_dm->KeyDownChar(L"up");
			Sleep(RandomNumber(80, 90));
			m_dm->KeyUpChar(L"up");
		}
		m_dm->KeyUpChar(L"left");//向左弹起
							   //m_dm->KeyUp(38);
		Sleep(RandomNumber(2000, 3000));
		if (m_dm->RunScript(L"乌鲁斯地图")) {
			m_dm->KeyDownChar(L"right");//向右按住
			for (size_t i = 0; i < 20; i++)
			{
				m_dm->KeyDownChar(L"up");
				Sleep(RandomNumber(80, 90));
				m_dm->KeyUpChar(L"up");
			}
			m_dm->KeyUpChar(L"right");//向左弹起
		}

	}
}

//退出自由市场
void CScriptMaple::ExitShiChang()
{
	if (m_dm->RunScript(L"自由市场")) {
		m_dm->KeyDownChar(L"left");//向左按住
		Sleep(RandomNumber(60, 90));
		for (size_t i = 0; i < 20; i++)
		{
			m_dm->KeyDownChar(L"up");
			Sleep(RandomNumber(80, 90));
			m_dm->KeyUpChar(L"up");
		}
		m_dm->KeyUpChar(L"left");//向左弹起
							   //m_dm->KeyUp(38);
		Sleep(RandomNumber(1000, 2000));
		if (m_dm->RunScript(L"自由市场")) {
			m_dm->KeyDownChar(L"right");//向右按住
			Sleep(500);
			for (size_t i = 0; i < 20; i++)
			{
				m_dm->KeyDownChar(L"up");
				Sleep(RandomNumber(80, 90));
				m_dm->KeyUpChar(L"up");
			}
			Sleep(RandomNumber(2000, 3000));
			m_dm->KeyUpChar(L"right");//向左弹起
		}

	}
}

//背包整理
bool CScriptMaple::ZhengLi()
{
	long x, y;
	m_dm->RunScript(L"背包线", &x, &y);
	CString str;
	str.Format(L"背包坐标%d", x);
	g_main_cwnd->AppendText(str);
	if (x > 0) {
		str.Format(L"开始整理");
		g_main_cwnd->AppendText(str);
		//点击装备栏
		m_dm->MoveTo(x + 10 + RandomNumber(1, 10), y + 5 + RandomNumber(1, 5));
		Sleep(RandomNumber(100, 300));
		m_dm->LeftClick();
		Sleep(RandomNumber(500, 1000));
		m_dm->RunScript(L"整理");
		Sleep(RandomNumber(1000, 1500));
		m_dm->MoveTo(x + 42 + RandomNumber(1, 10), y + 5 + RandomNumber(1, 5));
		Sleep(RandomNumber(100, 300));
		m_dm->LeftClick();
		Sleep(RandomNumber(500, 1000));
		m_dm->RunScript(L"整理");
		Sleep(RandomNumber(1000, 1500));
		m_dm->MoveTo(x + 75 + RandomNumber(1, 10), y + 5 + RandomNumber(1, 5));
		Sleep(RandomNumber(100, 300));
		m_dm->LeftClick();
		Sleep(RandomNumber(500, 1000));
		m_dm->RunScript(L"整理");
		Sleep(RandomNumber(1000, 1500));
		m_dm->MoveTo(x + RandomNumber(400, 500), y + RandomNumber(100, 500));

	}
	str.Format(L"整理结束");
	g_main_cwnd->AppendText(str);
	return true;
}
//切换线路
int CScriptMaple::LineSwitching()
{
	long x, y;
	m_dm->FindPic(558, 384, 938, 643, L"huanxian.bmp", L"202020", 0.95, 0, &x, &y);
	if (x == -1) {
		m_dm->KeyPress(27);
		Sleep(RandomNumber(200, 300));
	}
	else {
		Sleep(RandomNumber(200, 300));
		m_dm->KeyPress(13);
		Sleep(RandomNumber(200, 300));
	}

	if (g_main_cwnd->m_swichLine.GetCheck() == 1) {
		m_dm->FindPic(341, 241, 687, 399, L"xq27.bmp", L"202020", 0.95, 0, &x, &y);

	}
	else {
		m_dm->FindPic(611, 232, 695, 299, L"xq9.bmp", L"202020", 0.90, 0, &x, &y);

	}

//	m_dm->FindPic(611, 232, 695, 299, L"xq9.bmp", L"202020", 0.95, 0, &x, &y);
	if (x > 0) {
		Sleep(1000);
		m_dm->MoveTo(x + 7, y + 5);
		Sleep(500);
		m_dm->LeftDoubleClick();
		Sleep(500);
		Sleep(8000);
		return 1;
	}
	if (g_main_cwnd->m_swichLine.GetCheck() == 1) {
		m_dm->FindPic(341, 241, 687, 399, L"xq271.bmp", L"202020", 0.95, 0, &x, &y);

	}
	else {
		m_dm->FindPic(611, 232, 695, 299, L"xq91.bmp", L"202020", 0.90, 0, &x, &y);

	}
	
	
	if (x > 0) {
		Sleep(1000);
		m_dm->KeyPress(27);
		Sleep(1000);
		return 1;
	}

	return 0;
}
//丢弃物品
bool CScriptMaple::DropItem(CString& strWupin)
{
	long x, y;
	Sleep(RandomNumber(1500, 2000));
	m_dm->KeyPressChar(L"i");
	Sleep(RandomNumber(300, 500));
	//m_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
	if (m_dm->RunScript(L"背包线", &x, &y)) {
		m_dm->MoveTo(x + 40 + RandomNumber(1, 8), y + 5 + RandomNumber(2, 5));
		Sleep(RandomNumber(180, 320));
		m_dm->LeftClick();
		m_dm->MoveTo(x + 540 + RandomNumber(1, 80), y + 5 + RandomNumber(2, 50));
		Sleep(RandomNumber(1680, 2720));
		CString strZb = m_dm->FindPicEx(1, 1, 500, 600, L"wupinhj.bmp|wupinrj.bmp", L"202020", 0.9, 0);
		CStringArray arrZb;
		StringSplit(strZb, arrZb, '|');
		strWupin = m_dm->FindPicS(10, 10, 800, 600, L"bagBiao.bmp|bagDan.bmp|bagDan1.bmp|buJian.bmp|buJian1.bmp", L"202020", 0.9, 0, &x, &y);
		//查找补东西物品
		if (arrZb.GetCount() > 0) {
			for (size_t j = 0; j < arrZb.GetCount(); j++)
			{
				long nX1, nX2, nY1, nY2;
				if (m_dm->RunScript(L"确定"))
					m_dm->KeyPressChar(L"enter");
				CString strPoint = arrZb.GetAt(j);
				CStringArray arrPoint;
				StringSplit(strPoint, arrPoint, ',');
				nX1 = _wtoi(arrPoint.GetAt(1));
				nY1 = _wtoi(arrPoint.GetAt(2));
				m_dm->MoveToEx(nX1 + 10, nY1 + 10, 5, 10);
				Sleep(RandomNumber(1500, 2000));
				if (m_dm->RunScript(L"红卷")) {
					continue;
				}
				m_dm->LeftClick();
				Sleep(RandomNumber(380, 520));
				m_dm->MoveToEx(300, 30, 100, 20);
				Sleep(RandomNumber(380, 520));
				m_dm->LeftClick();
				Sleep(RandomNumber(500, 800));
				if (m_dm->RunScript(L"确定"))
					m_dm->KeyPressChar(L"enter");
				Sleep(RandomNumber(1000, 1520));
			}
		}
		m_dm->KeyPressChar(L"i");
		Sleep(RandomNumber(380, 520));
	}
	Sleep(RandomNumber(1500, 2000));
	return true;
}

//交易开始
bool CScriptMaple::Trading()
{
	long x, y, nX, nY;
	for (size_t i = 0; i < 15; i++)
	{
		
		m_dm->FindPic(0, 0, 1024, 700, L"jyWnd.bmp|jyWnd1.bmp|jyWnd2.bmp", L"101010", 1, 0, &nX, &nY);
		if (nX > 0) {//交易窗口
			Sleep(300);
			m_dm->FindPic(0, 0, 500, 700, L"kuoda.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {//窗口为小窗口
				Sleep(300);
				m_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
				if (x > 100) {//移动背包窗口
					m_dm->MoveToEx(x, y, 5, 5);
					m_dm->LeftDown();
					Sleep(RandomNumber(380, 550));
					m_dm->MoveTo(RandomNumber(90, 111), y);
					Sleep(RandomNumber(280, 350));
					m_dm->LeftUp();
					Sleep(RandomNumber(180, 350));
				}
			}
			//交易窗口存在 则检查窗口是否扩大
			m_dm->FindPic(0, 0, 500, 700, L"suoxiao.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {//缩小背包
				m_dm->MoveToEx(x + 1, y + 2, 5, 5);
				m_dm->LeftClick();
				Sleep(RandomNumber(80, 120));
			}
			else {
				Sleep(RandomNumber(1000, 1100));
				CString strJy = m_dm->FindPicEx(385, 277, 565, 439, L"bagKuang.bmp", L"202020", 1, 0);
				CStringArray arrJy;
				StringSplit(strJy, arrJy, '|');

				m_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {//获取背包坐标
					m_dm->MoveToEx(x - 40, y + 23, 5, 5);
					m_dm->LeftClick();
					Sleep(RandomNumber(180, 220));
					m_dm->MoveToEx(x - 40, y - 80, 55, 25);
					Sleep(RandomNumber(80, 120));
					Sleep(RandomNumber(1680, 2720));
					//查找装备栏装备
					//m_dm->FindPic(x - 70, y, x + 140, y + 300, L"ckTag.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {//移动到交易栏
								//交易金币
						CString strZb = m_dm->FindPicEx(x - 70, y, x + 140, y + 300, L"card1.bmp|card2.bmp|mofang.bmp|card3.bmp", L"202020", 0.9, 0);
						CStringArray arrZb;
						StringSplit(strZb, arrZb, '|');
						for (size_t i = 0; i < arrJy.GetCount(); i++)
						{
							if (i >= arrZb.GetCount()) {
								break;
							}
							//取装备坐标栏目坐标
							long nX1, nX2, nY1, nY2;
							CString strPoint = arrZb.GetAt(i);
							CStringArray arrPoint;
							StringSplit(strPoint, arrPoint, ',');
							nX1 = _wtoi(arrPoint.GetAt(1));
							nY1 = _wtoi(arrPoint.GetAt(2));
							strPoint = arrJy.GetAt(i);
							arrPoint.RemoveAll();
							StringSplit(strPoint, arrPoint, ',');
							nX2 = _wtoi(arrPoint.GetAt(1));
							nY2 = _wtoi(arrPoint.GetAt(2));
							Sleep(RandomNumber(80, 120));
							m_dm->MoveToEx(nX1 + 10, nY1 + 10, 5, 10);
							Sleep(RandomNumber(580, 720));
							m_dm->LeftClick();
							Sleep(RandomNumber(480, 620));
							m_dm->MoveToEx(nX2 + 10, nY2 + 10, 5, 10);
							Sleep(RandomNumber(580, 620));
							m_dm->LeftClick();
							Sleep(RandomNumber(1500, 1720));
						}

						Sleep(RandomNumber(1680, 2720));

						strZb = m_dm->FindPicEx(x - 70, y, x + 140, y + 300, L"card1.bmp|card2.bmp|mofang.bmp|card3.bmp", L"202020", 0.9, 0);
						arrZb.RemoveAll();
						StringSplit(strZb, arrZb, '|');
						strJy = m_dm->FindPicEx(385, 277, 565, 439, L"bagKuang.bmp", L"202020", 1, 0);
						arrJy.RemoveAll();
						StringSplit(strJy, arrJy, '|');



						if (arrZb.GetCount() == 0) {//装备栏物品已移动执行卡片切换
							if (m_dm->RunScript(L"背包线", &x, &y)) {//背包坐标

								Sleep(RandomNumber(180, 220));
								m_dm->MoveToEx(x + 70, y + 5, 5, 5);
								Sleep(RandomNumber(180, 220));
								m_dm->LeftClick();
								Sleep(RandomNumber(180, 220));


								Sleep(RandomNumber(200, 300));
								m_dm->MoveTo(x + 170, y - 55 - RandomNumber(1, 20));
								Sleep(RandomNumber(1680, 2720));
								strZb = m_dm->FindPicEx(x - 10, 0, x + 180, 700, L"bagYou.bmp", L"202020", 1, 0);
								arrZb.RemoveAll();
								StringSplit(strZb, arrZb, '|');

								for (size_t i = 0; i < arrJy.GetCount(); i++)
								{
									if (i >= arrZb.GetCount()) {
										break;
									}
									//取装备坐标栏目坐标
									long nX1, nX2, nY1, nY2;
									CString strPoint = arrZb.GetAt(i);
									CStringArray arrPoint;
									StringSplit(strPoint, arrPoint, ',');
									nX1 = _wtoi(arrPoint.GetAt(1));
									nY1 = _wtoi(arrPoint.GetAt(2));
									strPoint = arrJy.GetAt(i);
									arrPoint.RemoveAll();
									StringSplit(strPoint, arrPoint, ',');
									nX2 = _wtoi(arrPoint.GetAt(1));
									nY2 = _wtoi(arrPoint.GetAt(2));
									Sleep(RandomNumber(80, 120));
									m_dm->MoveToEx(nX1 + 10, nY1 + 10, 5, 10);
									Sleep(RandomNumber(580, 720));
									m_dm->LeftClick();
									Sleep(RandomNumber(480, 620));
									m_dm->MoveToEx(nX2 + 10, nY2 + 10, 5, 10);
									Sleep(RandomNumber(580, 620));
									m_dm->LeftClick();
									Sleep(RandomNumber(1500, 1720));
									//m_dm->RunScript(L"确定");
									if (m_dm->RunScript(L"确定")) {
										m_dm->KeyPress(13);
									}
									Sleep(RandomNumber(580, 620));
								}

								Sleep(RandomNumber(1680, 2720));
							}
						}

						m_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
						strZb = m_dm->FindPicEx(x - 70, y, x + 155, y + 300, L"bagYou.bmp", L"202020", 0.9, 0);
						arrZb.RemoveAll();
						StringSplit(strZb, arrZb, '|');
						strJy = m_dm->FindPicEx(385, 277, 565, 439, L"bagKuang.bmp", L"202020", 1, 0);
						arrJy.RemoveAll();
						StringSplit(strJy, arrJy, '|');

						if (arrZb.GetCount() <= 2) {//装备移动完成执行物品移动
							m_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
							if (x > 0) {
								m_dm->MoveToEx(x - 5, y + 23, 5, 5);
								Sleep(RandomNumber(180, 220));
								m_dm->LeftClick();
								Sleep(RandomNumber(180, 220));
								m_dm->MoveToEx(x - 40, y - 80, 55, 25);
								Sleep(RandomNumber(80, 120));
								Sleep(RandomNumber(1680, 2720));

								strZb = m_dm->FindPicEx(x - 100, 0, x + 140, 700, L"mofang.bmp|yaoshui.bmp|card3.bmp|wupinlj.bmp|wupinrj.bmp", L"202020", 1, 0);
								arrZb.RemoveAll();
								StringSplit(strZb, arrZb, '|');
								CString jinbi;
								if (arrJy.GetCount() > 0) {
									int nCount = arrZb.GetCount();
									for (size_t i = 0; i < arrJy.GetCount(); i++)
									{
										if (i >= arrZb.GetCount()) {
											break;
										}
										long nX1, nX2, nY1, nY2;
										CString strPoint = arrZb.GetAt(i);
										CStringArray arrPoint;
										StringSplit(strPoint, arrPoint, ',');
										nX1 = _wtoi(arrPoint.GetAt(1));
										nY1 = _wtoi(arrPoint.GetAt(2));
										strPoint = arrJy.GetAt(i);
										arrPoint.RemoveAll();
										StringSplit(strPoint, arrPoint, ',');
										nX2 = _wtoi(arrPoint.GetAt(1));
										nY2 = _wtoi(arrPoint.GetAt(2));
										Sleep(RandomNumber(80, 120));
										m_dm->MoveToEx(nX1 + 10, nY1 + 10, 20, 10);
										Sleep(RandomNumber(380, 520));
										m_dm->LeftClick();
										Sleep(RandomNumber(380, 520));
										m_dm->MoveToEx(nX2 + 10, nY2 + 10, 20, 10);
										Sleep(RandomNumber(580, 720));
										m_dm->LeftClick();
										Sleep(RandomNumber(580, 720));
										m_dm->FindPic(0, 0, 1024, 700, L"inputNum.bmp", L"101010", 1, 0, &x, &y);
										if (x > 0) {
											Sleep(RandomNumber(500, 1000));
											m_dm->KeyPress(13);
											Sleep(RandomNumber(300, 500));
										}
										Sleep(RandomNumber(1300, 2500));
									}
								}
								//改动
								m_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
								strZb = m_dm->FindPicEx(x - 100, 0, x + 140, 700, L"mofang.bmp|yaoshui.bmp|card3.bmp|wupinlj.bmp|wupinrj.bmp", L"202020", 1, 0);
								arrZb.RemoveAll();
								StringSplit(strZb, arrZb, '|');
								if (arrZb.GetCount() >= 0) {
									m_dm->FindPic(0, 4, 443, 800, L"bagMoney.bmp", L"202020", 0.8, 0, &x, &y);

									if (x > 0) {//识别金币
										jinbi = m_dm->Ocr(x + 58, y - 3, x + 145, y + 20, L"000000-050505", 0.9);
										if (_wtoi(jinbi) >= 0) {
											Sleep(2000);
											m_dm->FindPic(nX - 100, nY, nX, nY + 200, L"yaoshuiTag.bmp", L"101010", 0.9, 0, &x, &y);
											if (x > 0) {
												if (_wtoi(jinbi) > 0) {
													m_dm->MoveTo(nX + 55, nY + 208);
													m_dm->LeftClick();
													Sleep(1500);
													//m_dm->KeyPressStr(L"500", RandomNumber(300, 500));
													m_dm->SendString2(m_dm->GetBindWindow(), jinbi);
													Sleep(1500);
													m_dm->KeyPress(13);
													Sleep(2500);
												}
												m_dm->MoveToEx(nX + 10, nY + 2, 10, 5);
												Sleep(1500);
												m_dm->LeftClick();
												Sleep(1500);
												for (size_t i = 0; i < 5; i++)
												{
													CString strMap = m_dm->FindPicS(212, 131, 843, 650, L"yesJy.bmp|JyOk.bmp|jyMan.bmp", L"050505", 1, 0, &x, &y);
													if (strMap != "") {
														if (strMap == L"JyOk.bmp" || strMap == L"jyMan.bmp") {
															m_dm->KeyPress(13);
															Sleep(1500);
															m_State = 9;
															int nRoleNum = g_AccountFile.GetInt(NumberToString(m_Index + 1), L"RoleNum");
															if (jinbi == L"0") {
																CString strJin = g_AccountFile.GetString(NumberToString(m_Index + 1), L"bbjb");
																CString strNoMoney;
																if (strJin == "") {
																	strNoMoney = NumberToString(nRoleNum); //1
																}
																else {
																	strNoMoney = strJin + L"," + NumberToString(nRoleNum);//1,2  1,2,3
																}
																g_AccountFile.SetString(NumberToString(m_Index + 1), L"bbjb", strNoMoney);
																g_main_cwnd->m_list_info.SetItemText(m_Index, 8, strNoMoney);
															}
															return true;
														}
														else
														{
															m_dm->KeyPress(13);
															Sleep(1500);
														}
													}
													Sleep(500);

												}
											}
										}
									}
								}


							}
						}
					}
				}
				else {
					m_dm->KeyPress(73);
				}

			}
		}
		else {//执行交易动作
			m_dm->FindPic(16, 493, 347, 685, L"rightWnd.bmp", L"202020", 0.90, 0, &x, &y);
			if (x == -1) {
				m_dm->MoveTo(171, 618);
				Sleep(RandomNumber(300, 400));
				m_dm->RightClick();
				Sleep(RandomNumber(500, 800));
			}
			m_dm->FindPic(16, 493, 347, 685, L"rightWnd.bmp", L"202020", 0.90, 0, &x, &y);
			if (x>0) {
				m_dm->MoveTo(x + 10, y + 3);
				Sleep(RandomNumber(500, 600));
				m_dm->LeftClick();
				Sleep(RandomNumber(500, 600));
			}
		}
		Sleep(5000);
	}
	m_dm->FindPic(0, 0, 1024, 700, L"jyWndNo.bmp|jyWnd.bmp|jyWnd1.bmp|jyWnd2.bmp|jyWndNo1.bmp", L"101010", 1, 0, &x, &y);
	if (x > 0) {
		m_dm->MoveTo(x + 10 + RandomNumber(1, 33), y + RandomNumber(30, 33));
		m_dm->LeftClick();
		Sleep(RandomNumber(100, 200));
	}

}

//补充材料
bool CScriptMaple::SuppLies(CString strWuPin)
{
	long x, y;
	m_dm->RunScript(L"材料商人");
	g_main_cwnd->AppendText(L"找到npc材料商人");

	Sleep(RandomNumber(500, 1000));
	if (m_dm->RunScript(L"买卖窗口", &x, &y)) {
		//点击消耗栏
		m_dm->Click(x + 202, y + 93, 10, 5);
		Sleep(RandomNumber(500, 1000));
		if (m_dm->RunScript(L"选中消耗")) {
			if (strWuPin == L"bagBiao.bmp" || strWuPin == L"bagDan.bmp" || strWuPin == L"bagDan1.bmp") {
				g_main_cwnd->AppendText(L"补充开始");
				int k = 0;
				for (size_t i = 0; i < 5; i++)
				{
					if (m_dm->RunScript(L"补充按钮")) {
						Sleep(RandomNumber(500, 1000));
						m_dm->KeyPressChar(L"enter");
						Sleep(RandomNumber(500, 1000));
						k++;
					}
				}
				if (k > 0) {
					if (m_dm->RunScript(L"确定")) {
						Sleep(RandomNumber(500, 1000));
						m_dm->KeyPressChar(L"enter");
						Sleep(RandomNumber(500, 1000));
					}
					if (m_dm->RunScript(L"买卖窗口", &x, &y)) {
						Sleep(RandomNumber(500, 1000));
						m_dm->Click(x + 100, y + 45, 20, 5);
					}
					return true;
				}
			}
			if (strWuPin == L"buJian.bmp" || strWuPin == L"buJian1.bmp") {

				m_dm->MoveTo(x + 10 + RandomNumber(1, 5), y + 193 + RandomNumber(1, 15));
				for (size_t i = 0; i < 18; i++)
				{
					m_dm->WheelDown();
					Sleep(RandomNumber(100, 250));
				}
				Sleep(RandomNumber(1000, 2500));
				CString strJian = strWuPin == L"buJian.bmp" ? L"shopjian.bmp" : L"shopjian1.bmp";
				m_dm->FindPic(10, 10, 800, 700, strJian, L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					m_dm->Click(x + 5, y + 5, 10, 5);
					m_dm->LeftClick();
					Sleep(RandomNumber(2000, 2550));
					//m_dm->KeyPressChar(L"enter");
					//m_dm->KeyDownChar(L"enter");
					//
					m_dm->KeyPressChar(L"enter");
					Sleep(RandomNumber(500, 1000));
					//m_dm->KeyUpChar(L"enter");
				}
				if (m_dm->RunScript(L"确定", &x, &y)) {
					/*m_dm->Click(x + 5, y + 5, 20, 5);
					Sleep(RandomNumber(500, 1000));*/
					m_dm->KeyPressChar(L"enter");
					Sleep(RandomNumber(500, 1000));
				}
				m_dm->FindPic(482, 228, 800, 647, strWuPin, L"050505", 0.9, 0, &x, &y);
				if (x > 0) {

					if (m_dm->RunScript(L"买卖窗口", &x, &y)) {
						Sleep(RandomNumber(500, 1000));
						m_dm->Click(x + 100, y + 45, 20, 5);
					}
					return true;
				}

				//m_dm->MiddleUp();

			}
		}
	}

	if (m_dm->RunScript(L"确定", &x, &y)) {
		/*m_dm->Click(x + 5, y + 5, 20, 5);
		Sleep(RandomNumber(500, 1000));*/
		m_dm->KeyPressChar(L"enter");
		Sleep(RandomNumber(500, 1000));
	}
	if (m_dm->RunScript(L"买卖窗口", &x, &y)) {
		Sleep(RandomNumber(500, 1000));
		m_dm->Click(x + 100, y + 45, 20, 5);
	}
	return true;
}


//设定子线程大漠
void CScriptMaple::SetSubDm(CDm * dm)
{
	m_SubDm = dm;
}


//检测游戏
void CScriptMaple::CheckException()
{
	//if (m_SubDm != NULL) {
	//	long hwnd = m_SubDm->FindWindow(L"MapleStoryClass", L"MapleStory");
	//	if (m_SubDm->GetBindWindow() != hwnd && m_SubDm->GetBindWindow() != 0) {
	//		m_SubDm->UnBindWindow();
	//	}
	//	if (m_SubDm->GetBindWindow() == 0 && hwnd != 0) {
	//		m_SubDm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
	//	}
	//	if (hwnd == 0 && m_CheckState==true) {
	//		m_State = 0;
	//		m_Flag = false;
	//		m_CheckState = false;
	//	}
	//}
}

bool CScriptMaple::FindHwnd()
{
	long hwnd = m_dm->FindWindow(L"MapleStoryClass", L"MapleStory");
	if (hwnd == 0) {
		return false;
	}
	else {
		return true;
	}
}

int CScriptMaple::GetState() const
{
	return m_State;
}


//选择进入鲁塔地图
void CScriptMaple::LoginBoss() {
	//进入游戏后小地图是否开启
	//使用被动技能 2，3
	
	m_dm->RunScript(L"关闭广告");
	m_dm->RunScript(L"关闭广告1");
	m_dm->RunScript(L"关闭广告2");
	m_dm->RunScript(L"登录确定");

	if (m_dm->RunScript(L"地图巨大树根")) {
		//领取钥匙
		m_dm->Delays(500, 1000);
		m_dm->RunScript(L"黄色灯泡");
		m_dm->Delays(500, 1000);
		m_dm->RunScript(L"领取钥匙");

		m_dm->RunScript(L"退出确定1");


		//设置状态为2
		m_dm->Delays(200, 300);
		m_dm->KeyPressChar(L"1");
		m_dm->Delays(500, 800);
		m_dm->KeyPressChar(L"2");
		m_dm->Delays(200, 300);
		m_dm->KeyPressChar(L"3");
		m_dm->Delays(200, 300);
		g_AccountFile.SetInt(NumberToString(m_Index + 1),L"state", 2);
	}
	else {
		//位置在交易地图则退出交易地图
		if (m_dm->RunScript(L"交易地图")) {
			m_dm->KeyPressChar(L"up");
		}
		//执行进入wls操作
		if (m_dm->RunScript(L"冰峰雪域地图") || m_dm->RunScript(L"导航按钮")) {
			//选择进入地图巨大树根
		}
		//退出扎昆
		ExitZkjt();
		ExitZkrk();
	}
}

void  CScriptMaple::DoWorkBoss() {

	//进入游戏开启被动
	//m_dm->KeyPressChar(L"2");
	//m_dm->Delays(500, 1000);
	//m_dm->KeyPressChar(L"3");
	m_dm->RunScript(L"领取钥匙");
	m_State = g_AccountFile.GetInt(NumberToString(m_Index + 1), L"state");
	while (m_Flag) {
		//状态
		switch (m_State)
		{
		case 0://进入游戏状态为0
			LoginBoss();
			break;
		case 2://开始
			BossBanBan();
			break;
		default:
			break;
		}
	}

}
//Boss 半半
void CScriptMaple::BossBanBan() {
	for (size_t j = 0; j < 5; j++)
	{
		if (m_dm->RunScript(L"地图巨大树根")) {
			//移动到办办地图
		}
		if (m_dm->RunScript(L"地图东边庭园")) {
			m_dm->Delays(1000, 1500);
			MoveToBossBanBan();
			m_dm->Delays(300, 500);
			if (m_dm->RunScript(L"退出确定1")) {
				m_dm->Delays(2000, 3000);
			}
			
		}
		if (m_dm->RunScript(L"地图时间缝隙")) {
			m_dm->Delays(1000, 1500);
			for (size_t i = 0; i < 3; i++)
			{
				m_dm->MoveToEx(830, 558, 5, 5);
				m_dm->LeftClick();
				m_dm->Delays(300, 500);
				AttackBoss();
			}
		}
		


	}


}
//Boss 腥血女王
void CScriptMaple::BossXingXueNvWang() {
	m_dm->Delays(300, 500);
	for (size_t j = 0; j < 5; j++)
	{
		if (m_dm->RunScript(L"地图巨大树根")) {

		}
		if (m_dm->RunScript(L"地图南部平原")) {
			MoveToBossXingXue();//进入boss
			m_dm->Delays(2000, 3000);
		}
		if (m_dm->RunScript(L"地图女王之城")) {
			m_dm->Delays(1200, 1300);
			for (size_t i = 0; i < 7; i++)
			{
				m_dm->MoveToEx(890, 346, 5, 10);
				m_dm->LeftClick();
				m_dm->Delays(300, 500);
			}
			AttackBoss();//攻击boss
			FindItem();//开启宝箱
			break;
		}
		//

	}

	//退出Boss

}
//清怪
void CScriptMaple::ClearMonster() {
	//到达地图开始清怪
	//左跳打
	//右跳打
	//m_dm->KeyDownChar(L"left");
	//m_dm->Delays(650,670);
	//m_dm->KeyUpChar(L"left");
	//return;
	m_dm->Delays(300, 500);
	m_dm->KeyDownChar(L"left");
	for (size_t i = 0; i < 3; i++)
	{
		m_dm->KeyPressChar(L"shift");
		m_dm->Delays(300, 500);
	}
	m_dm->KeyUpChar(L"left");

	m_dm->Delays(300, 500);
	m_dm->KeyDownChar(L"right");
	for (size_t i = 0; i < 45; i++)
	{
		Sleep(RandomNumber(80, 120));
		m_dm->KeyDownChar(L"alt");
		Sleep(RandomNumber(60, 100));
		m_dm->KeyUpChar(L"alt");
		Sleep(RandomNumber(50, 120));
		m_dm->KeyPressChar(L"shift");
		Sleep(RandomNumber(150, 180));
		ShowLog(L"次数" + NumberToString(i));
	}
	m_dm->KeyUpChar(L"right");
	m_dm->Delays(300, 500);



}

//进入Boss腥红
void CScriptMaple::MoveToBossXingXue() {

	ClearMonster();
	m_dm->KeyDownChar(L"left");
	m_dm->Delays(1500, 2500);
	for (size_t i = 0; i < 45; i++)
	{
		m_dm->KeyPressChar(L"up");
		//检查怪物是否清空
		ShowLog(L"次数" + NumberToString(i));
		m_dm->Delays(30, 50);
	}
	m_dm->KeyUpChar(L"left");
	m_dm->RunScript(L"退出确定1");
	m_dm->Delays(200, 300);
}

void CScriptMaple::BuXue() {
	if (m_dm->RunScript(L"补血")) {
		m_dm->Delays(200, 300);
		m_dm->KeyPressChar(L"end");

	}
}

void CScriptMaple::AttackBoss() {
	m_dm->Delays(500,600);
	m_dm->KeyPressChar(L"pgdn");
	BuXue();
	m_dm->Delays(500, 800);
	m_dm->KeyPressChar(L"r");
	BuXue();
	m_dm->Delays(500, 800);
	m_dm->KeyPressChar(L"delete");
	BuXue();
	m_dm->Delays(500, 800);
	m_dm->KeyPressChar(L"pgup");
	BuXue();
	m_dm->Delays(500, 800);
	m_dm->KeyPressChar(L"insert");
	BuXue();
	m_dm->Delays(500, 800);
	for (size_t i = 0; i < 50; i++)
	{
		m_dm->KeyPressChar(L"shift");
		m_dm->Delays(200, 300);
		ShowLog(L"攻击次数" + NumberToString(i));
		BuXue();
		if (m_dm->RunScript(L"扎昆物品") || m_dm->RunScript(L"女王宝箱")) {
			break;
		}
	}
}


void CScriptMaple::FindItem() {
	m_dm->Delays(500, 1000);
	m_dm->KeyDownChar(L"right");
	m_dm->delay(2000);
	m_dm->KeyUpChar(L"right");
	m_dm->Delays(200, 300);
	m_dm->KeyPressChar(L"ctrl");
}

void CScriptMaple::MoveToBossBanBan(){
	m_dm->Delays(300, 500);
	ClearMonster();
	m_dm->Delays(300, 500);
	m_dm->KeyDownChar(L"left");
	m_dm->Delays(650,660);
	m_dm->KeyUpChar(L"left");

	m_dm->Delays(300, 500);
	m_dm->KeyPressChar(L"alt");
	m_dm->Delays(300, 500);
	m_dm->KeyPressChar(L"up");
}